// 重置宿舍数据的脚本
// 由于localStorage只能在浏览器环境中使用，这个脚本需要在浏览器控制台中运行

console.log('宿舍数据重置脚本');
console.log('注意：此脚本需要在浏览器控制台中运行');

// 在浏览器环境中执行以下代码
if (typeof window !== 'undefined' && typeof localStorage !== 'undefined') {
    // 清除所有相关数据
    localStorage.removeItem('dormitoryStorage');
    console.log('已清除宿舍数据');
    
    // 重新生成宿舍数据
    const dormitories = [];
    let dormitoryId = 1;
    
    // 生成随机入住人数的函数
    const getRandomOccupancy = (capacity) => {
        return Math.floor(Math.random() * (capacity + 1));
    };
    
    // 生成创建时间的函数
    const getRandomDate = () => {
        return new Date().toISOString();
    };
    
    // 生成所有宿舍数据
    function generateAllDormitories() {
        // 一号楼男生宿舍
        const building1Floors = [1, 2, 3, 4, 5];
        building1Floors.forEach(floor => {
            for (let roomNum = 1; roomNum <= 10; roomNum++) {
                const capacity = 4;
                const currentOccupancy = getRandomOccupancy(capacity);
                dormitories.push({
                    id: String(dormitoryId++),
                    building: '一号楼',
                    roomNumber: `${String(roomNum).padStart(3, '0')}`,
                    type: 'male',
                    capacity: capacity,
                    currentOccupancy: currentOccupancy,
                    students: [],
                    floor: floor,
                    status: 'active',
                    notes: '男生宿舍',
                    createdAt: getRandomDate(),
                    updatedAt: getRandomDate()
                });
            }
        });
        
        // 二号楼女生宿舍
        const building2Floors = [1, 2, 3, 4, 5];
        building2Floors.forEach(floor => {
            for (let roomNum = 1; roomNum <= 10; roomNum++) {
                const capacity = 4;
                const currentOccupancy = getRandomOccupancy(capacity);
                dormitories.push({
                    id: String(dormitoryId++),
                    building: '二号楼',
                    roomNumber: `${String(roomNum).padStart(3, '0')}`,
                    type: 'female',
                    capacity: capacity,
                    currentOccupancy: currentOccupancy,
                    students: [],
                    floor: floor,
                    status: 'active',
                    notes: '女生宿舍',
                    createdAt: getRandomDate(),
                    updatedAt: getRandomDate()
                });
            }
        });
        
        // 学三舍男生宿舍
        const xuesansheFloors = [1, 2, 3, 4];
        xuesansheFloors.forEach(floor => {
            for (let roomNum = 1; roomNum <= 8; roomNum++) {
                const capacity = 6;
                const currentOccupancy = getRandomOccupancy(capacity);
                dormitories.push({
                    id: String(dormitoryId++),
                    building: '学三舍',
                    roomNumber: `${String(roomNum).padStart(3, '0')}`,
                    type: 'male',
                    capacity: capacity,
                    currentOccupancy: currentOccupancy,
                    students: [],
                    floor: floor,
                    status: 'active',
                    notes: '男生宿舍',
                    createdAt: getRandomDate(),
                    updatedAt: getRandomDate()
                });
            }
        });
        
        // 学四舍女生宿舍
        const xuesisheFloors = [1, 2, 3, 4];
        xuesisheFloors.forEach(floor => {
            for (let roomNum = 1; roomNum <= 8; roomNum++) {
                const capacity = 6;
                const currentOccupancy = getRandomOccupancy(capacity);
                dormitories.push({
                    id: String(dormitoryId++),
                    building: '学四舍',
                    roomNumber: `${String(roomNum).padStart(3, '0')}`,
                    type: 'female',
                    capacity: capacity,
                    currentOccupancy: currentOccupancy,
                    students: [],
                    floor: floor,
                    status: 'active',
                    notes: '女生宿舍',
                    createdAt: getRandomDate(),
                    updatedAt: getRandomDate()
                });
            }
        });
        
        // 五号楼女生宿舍
        const building5Floors = [1, 2, 3, 4];
        building5Floors.forEach(floor => {
            for (let roomNum = 1; roomNum <= 12; roomNum++) {
                const capacity = 4;
                const currentOccupancy = getRandomOccupancy(capacity);
                dormitories.push({
                    id: String(dormitoryId++),
                    building: '五号楼',
                    roomNumber: `${String(roomNum).padStart(3, '0')}`,
                    type: 'female',
                    capacity: capacity,
                    currentOccupancy: currentOccupancy,
                    students: [],
                    floor: floor,
                    status: 'active',
                    notes: '女生宿舍',
                    createdAt: getRandomDate(),
                    updatedAt: getRandomDate()
                });
            }
        });
        
        // 学五舍男生宿舍
        const xuewusheFloors = [1, 2, 3, 5];
        xuewusheFloors.forEach(floor => {
            for (let roomNum = 1; roomNum <= 10; roomNum++) {
                const capacity = 6;
                const currentOccupancy = getRandomOccupancy(capacity);
                dormitories.push({
                    id: String(dormitoryId++),
                    building: '学五舍',
                    roomNumber: `${String(roomNum).padStart(3, '0')}`,
                    type: 'male',
                    capacity: capacity,
                    currentOccupancy: currentOccupancy,
                    students: [],
                    floor: floor,
                    status: 'active',
                    notes: '男生宿舍',
                    createdAt: getRandomDate(),
                    updatedAt: getRandomDate()
                });
            }
        });
        
        // 留学生公寓
        const foreignStudentsFloors = [1, 2, 3];
        foreignStudentsFloors.forEach(floor => {
            for (let roomNum = 1; roomNum <= 6; roomNum++) {
                const capacity = 2;
                const currentOccupancy = getRandomOccupancy(capacity);
                dormitories.push({
                    id: String(dormitoryId++),
                    building: '留学生公寓',
                    roomNumber: `${String(roomNum).padStart(3, '0')}`,
                    type: 'mixed',
                    capacity: capacity,
                    currentOccupancy: currentOccupancy,
                    students: [],
                    floor: floor,
                    status: 'active',
                    notes: '混合宿舍',
                    createdAt: getRandomDate(),
                    updatedAt: getRandomDate()
                });
            }
        });
        
        // 研究生楼女生部分
        for (let floor = 1; floor <= 2; floor++) {
            for (let roomNum = 1; roomNum <= 8; roomNum++) {
                const capacity = 2;
                const currentOccupancy = getRandomOccupancy(capacity);
                dormitories.push({
                    id: String(dormitoryId++),
                    building: '研究生楼',
                    roomNumber: `F${floor}W${String(roomNum).padStart(2, '0')}`,
                    type: 'female',
                    capacity: capacity,
                    currentOccupancy: currentOccupancy,
                    students: [],
                    floor: floor,
                    status: 'active',
                    notes: '女生宿舍',
                    createdAt: getRandomDate(),
                    updatedAt: getRandomDate()
                });
            }
        }
        
        // 研究生楼男生部分
        for (let floor = 1; floor <= 2; floor++) {
            for (let roomNum = 1; roomNum <= 8; roomNum++) {
                const capacity = 2;
                const currentOccupancy = getRandomOccupancy(capacity);
                dormitories.push({
                    id: String(dormitoryId++),
                    building: '研究生楼',
                    roomNumber: `F${floor}M${String(roomNum).padStart(2, '0')}`,
                    type: 'male',
                    capacity: capacity,
                    currentOccupancy: currentOccupancy,
                    students: [],
                    floor: floor,
                    status: 'active',
                    notes: '男生宿舍',
                    createdAt: getRandomDate(),
                    updatedAt: getRandomDate()
                });
            }
        }
        
        return dormitories;
    }
    
    // 生成所有宿舍
    generateAllDormitories();
    
    // 保存到localStorage
    localStorage.setItem('dormitoryStorage', JSON.stringify(dormitories));
    
    console.log(`宿舍数据生成完成，共生成 ${dormitories.length} 个宿舍`);
    
    // 显示楼栋统计
    const buildings = [...new Set(dormitories.map(d => d.building))];
    console.log('生成的楼栋:', buildings.join(', '));
    
    buildings.forEach(building => {
        const count = dormitories.filter(d => d.building === building).length;
        console.log(`- ${building}: ${count} 个宿舍`);
    });
    
    console.log('请刷新页面查看更新后的宿舍数据');
} else {
    console.error('此脚本需要在浏览器环境中运行');
    console.log('请在浏览器中打开应用，然后按F12打开控制台，复制以下代码执行：');
    
    const codeToRun = `
// 清除并重新生成宿舍数据
localStorage.removeItem('dormitoryStorage');
const dormitories = [];
let dormitoryId = 1;

// 生成随机入住人数
const getRandomOccupancy = (capacity) => Math.floor(Math.random() * (capacity + 1));
// 生成时间戳
const getRandomDate = () => new Date().toISOString();

// 生成所有宿舍数据
// 一号楼男生宿舍
[1,2,3,4,5].forEach(floor => {
  for (let roomNum = 1; roomNum <= 10; roomNum++) {
    dormitories.push({
      id: String(dormitoryId++),
      building: '一号楼',
      roomNumber: String(roomNum).padStart(3, '0'),
      type: 'male',
      capacity: 4,
      currentOccupancy: getRandomOccupancy(4),
      students: [],
      floor: floor,
      status: 'active',
      notes: '男生宿舍',
      createdAt: getRandomDate(),
      updatedAt: getRandomDate()
    });
  }
});

// 二号楼女生宿舍
[1,2,3,4,5].forEach(floor => {
  for (let roomNum = 1; roomNum <= 10; roomNum++) {
    dormitories.push({
      id: String(dormitoryId++),
      building: '二号楼',
      roomNumber: String(roomNum).padStart(3, '0'),
      type: 'female',
      capacity: 4,
      currentOccupancy: getRandomOccupancy(4),
      students: [],
      floor: floor,
      status: 'active',
      notes: '女生宿舍',
      createdAt: getRandomDate(),
      updatedAt: getRandomDate()
    });
  }
});

// 学三舍男生宿舍
[1,2,3,4].forEach(floor => {
  for (let roomNum = 1; roomNum <= 8; roomNum++) {
    dormitories.push({
      id: String(dormitoryId++),
      building: '学三舍',
      roomNumber: String(roomNum).padStart(3, '0'),
      type: 'male',
      capacity: 6,
      currentOccupancy: getRandomOccupancy(6),
      students: [],
      floor: floor,
      status: 'active',
      notes: '男生宿舍',
      createdAt: getRandomDate(),
      updatedAt: getRandomDate()
    });
  }
});

// 学四舍女生宿舍
[1,2,3,4].forEach(floor => {
  for (let roomNum = 1; roomNum <= 8; roomNum++) {
    dormitories.push({
      id: String(dormitoryId++),
      building: '学四舍',
      roomNumber: String(roomNum).padStart(3, '0'),
      type: 'female',
      capacity: 6,
      currentOccupancy: getRandomOccupancy(6),
      students: [],
      floor: floor,
      status: 'active',
      notes: '女生宿舍',
      createdAt: getRandomDate(),
      updatedAt: getRandomDate()
    });
  }
});

// 五号楼女生宿舍
[1,2,3,4].forEach(floor => {
  for (let roomNum = 1; roomNum <= 12; roomNum++) {
    dormitories.push({
      id: String(dormitoryId++),
      building: '五号楼',
      roomNumber: String(roomNum).padStart(3, '0'),
      type: 'female',
      capacity: 4,
      currentOccupancy: getRandomOccupancy(4),
      students: [],
      floor: floor,
      status: 'active',
      notes: '女生宿舍',
      createdAt: getRandomDate(),
      updatedAt: getRandomDate()
    });
  }
});

// 学五舍男生宿舍
[1,2,3,5].forEach(floor => {
  for (let roomNum = 1; roomNum <= 10; roomNum++) {
    dormitories.push({
      id: String(dormitoryId++),
      building: '学五舍',
      roomNumber: String(roomNum).padStart(3, '0'),
      type: 'male',
      capacity: 6,
      currentOccupancy: getRandomOccupancy(6),
      students: [],
      floor: floor,
      status: 'active',
      notes: '男生宿舍',
      createdAt: getRandomDate(),
      updatedAt: getRandomDate()
    });
  }
});

// 留学生公寓
[1,2,3].forEach(floor => {
  for (let roomNum = 1; roomNum <= 6; roomNum++) {
    dormitories.push({
      id: String(dormitoryId++),
      building: '留学生公寓',
      roomNumber: String(roomNum).padStart(3, '0'),
      type: 'mixed',
      capacity: 2,
      currentOccupancy: getRandomOccupancy(2),
      students: [],
      floor: floor,
      status: 'active',
      notes: '混合宿舍',
      createdAt: getRandomDate(),
      updatedAt: getRandomDate()
    });
  }
});

// 研究生楼女生部分
for (let floor = 1; floor <= 2; floor++) {
  for (let roomNum = 1; roomNum <= 8; roomNum++) {
    dormitories.push({
      id: String(dormitoryId++),
      building: '研究生楼',
      roomNumber: \`F\${floor}W\${String(roomNum).padStart(2, '0')}\`,
      type: 'female',
      capacity: 2,
      currentOccupancy: getRandomOccupancy(2),
      students: [],
      floor: floor,
      status: 'active',
      notes: '女生宿舍',
      createdAt: getRandomDate(),
      updatedAt: getRandomDate()
    });
  }
}

// 研究生楼男生部分
for (let floor = 1; floor <= 2; floor++) {
  for (let roomNum = 1; roomNum <= 8; roomNum++) {
    dormitories.push({
      id: String(dormitoryId++),
      building: '研究生楼',
      roomNumber: \`F\${floor}M\${String(roomNum).padStart(2, '0')}\`,
      type: 'male',
      capacity: 2,
      currentOccupancy: getRandomOccupancy(2),
      students: [],
      floor: floor,
      status: 'active',
      notes: '男生宿舍',
      createdAt: getRandomDate(),
      updatedAt: getRandomDate()
    });
  }
}

// 保存数据
localStorage.setItem('dormitoryStorage', JSON.stringify(dormitories));
console.log('宿舍数据已生成:', dormitories.length, '个宿舍');
console.log('楼栋列表:', [...new Set(dormitories.map(d => d.building))]);
`;
    
    console.log(codeToRun);
}